package general;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.context.AdfFacesContext;

import org.apache.myfaces.trinidad.component.UIXSwitcher;


//import oracle.adf.view.faces.component.UIXSwitcher;


public class BeanDashBoard {

    public void setDashBoards(List<BeanDashBoard.Dashbord> dashBoards) {
        this.dashBoards = dashBoards;
    }

    public List<BeanDashBoard.Dashbord> getDashBoards() {
        return dashBoards;
    }

    public class Dashbord {
        private String name;
        private boolean vizible;
        private String icon;
        private String iconDisabled;

        public Dashbord() {
        }

        public Dashbord(String name, boolean vizible, String icon, String iconDisabled) {
            this.name = name;
            this.vizible = vizible;
            this.icon = icon;
            this.iconDisabled = iconDisabled;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }


        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getIcon() {
            return icon;
        }

        public void setIconDis(String iconDisabled) {
            this.iconDisabled = iconDisabled;
        }

        

        public void setVizible(boolean vizible) {
            this.vizible = vizible;
        }

        public boolean isVizible() {
            return vizible;
        }

        public String getIconDisabled() {
            return iconDisabled;
        }
    }


    List<Dashbord> dashBoards = new ArrayList<Dashbord>();

    public BeanDashBoard() {
        super();
        Dashbord x = new Dashbord("Alerte", true, "img.jpg", "img.jpg");
        dashBoards.add(x);
        x = new Dashbord("Coco", true, "img.jpg", "img.jpg");
        dashBoards.add(x);
        x = new Dashbord("Info", true, "img.jpg", "img.jpg");
        dashBoards.add(x);
        x = new Dashbord("Studenti", true, "img.jpg", "img.jpg");
        dashBoards.add(x);
        x = new Dashbord("Note", false, "img.jpg", "img.jpg");
        dashBoards.add(x);

    }


    public UIXSwitcher switcher_dashboard;
    private String dashMaximized;

    public void operateDashboards(ActionEvent e) {
        {
            Object facet = e.getComponent().getAttributes().get("FACET");
            if (facet != null) {
                setDashMaximized(facet.toString());
                AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
                adfFacesContext.addPartialTarget(switcher_dashboard);
            }
        }

    }

    public void visibleDashboards(ActionEvent e) {
        Object dashName = e.getComponent().getAttributes().get("dashName");
        Object visible = e.getComponent().getAttributes().get("visible");
        if (dashName != null && visible != null) {
            Dashbord d = getDash(dashName.toString());
            d.setVizible(Boolean.parseBoolean(visible.toString()));
            AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
            adfFacesContext.addPartialTarget(switcher_dashboard);
        }
    }

    public Dashbord getDash(String name) {
        for (Dashbord d : dashBoards)
            if (d.getName().equals(name))
                return d;
        return null;
    }


    public void setDashMaximized(String dashMaximized) {
        this.dashMaximized = dashMaximized;
    }

    public String getDashMaximized() {
        return dashMaximized;
    }

    public void setSwitcher_dashboard(UIXSwitcher switcher_dashboard) {
        this.switcher_dashboard = switcher_dashboard;
    }

    public UIXSwitcher getSwitcher_dashboard() {
        return switcher_dashboard;
    }
    
    public String maximized(String name){
        return name.concat("_maximized");
        }
}
